<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/tree.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript">

 var currentAreaName="";
 var currentIsEdit='';
 var currentBuildingId='';
 var hasMoreProject='';
 var allowBuildView=false;

   function selectItem(itemId){
      if(tree.getLevel(itemId)==2){
	      document.getElementById("buildingName").value=tree.getItemText(itemId);
	      var areaId=tree.getParentId(itemId);
	      setAreaName(tree.getItemText(areaId));

         if(itemId.indexOf("_")>-1){
         itemId=itemId.substring(itemId.indexOf("_")+1,itemId.length);
         }

         if(areaId.indexOf("_")>-1){
         	areaId=areaId.substring(areaId.indexOf("_")+1,areaId.length);
         }
      	 currentBuildingId=itemId;
         document.getElementById("areaId").value=areaId;
         document.getElementById("projectId").value=tree.getUserData(itemId,"projectId");
         hasMoreProject=tree.getUserData(areaId,"hasMoreProject");

         document.getElementById("searchBuildingForm").action="${ctx}/house_buildingAction.do?method=initBuildingMain&buildingId="+itemId;

	     document.getElementById("searchBuildingForm").submit();

	     processButtonStatus(false);

	  } else if(tree.getLevel(itemId)==1){ //当选择的为第一个节点时,需要禁用删除按钮,修改修改URL
         currentBuildingId='';
         setAreaName(tree.getItemText(itemId));

	     if(itemId.indexOf("_")>-1){
          itemId=itemId.substring(itemId.indexOf("_")+1,itemId.length);
         }
         document.getElementById("areaId").value=itemId;
         hasMoreProject=tree.getUserData(itemId,"hasMoreProject");
		 document.all.mainFrame.src = "${ctx}/house_areaAction.do?method=initAreaBaseMain&areaId=" + itemId;
		 //设置按钮状态
		 processButtonStatus(true);
	    }
   }

   function refreshTree(tempbuildingId){

       if(tempbuildingId!=null){
         currentBuildingId=tempbuildingId;

       }
      tree.deleteChildItems(tree.rootId);
       if(currentIsEdit=='delete'){
		tree.loadXML("${ctx}/house_areaAction.do?method=getAreaTreeData",callbackTree);
		}else {

        tree.loadXML("${ctx}/house_areaAction.do?method=getAreaTreeData",EditCallbackTree);
		}
	}

	function EditCallbackTree(){
	  tree.openItem();
      tree.selectItem();
      var tempStr=tree.getSubItems(tree.getSelectedItemId());
     var tempArray=tempStr.split(",");
     tempStr=null;
     var isFisrt=false;
      for(var i=0;i<tempArray.length;i++){
         if(tempArray[i].indexOf("_")>-1){
           if((tempArray[i].substring(tempArray[i].indexOf("_")+1,tempArray[i].length))==currentBuildingId){
           tree.selectItem(tempArray[i]);
           tempArray=null;
           isFisrt=true;
           break;
           }
         }
      }
      if(!isFisrt) tree.selectItem(currentBuildingId);

      refleshFrame();

	}


	function refleshFrame(){
	    if(window.frames["mainFrame"].listType=='buildingDetail' && currentIsEdit=='edit'){
	      window.frames["mainFrame"].refleshFrame();
	    }else{
	      var itemId = tree.getSelectedItemId();   //id获得
   	      selectItem(itemId);
	    }
	}

	function refleshTreeForArea(){
	currentBuildingId='';
	currentIsEdit='';
	tree.deleteChildItems(tree.rootId);
	tree.loadXML("${ctx}/house_areaAction.do?method=getAreaTreeData",callbackTree);
	}

   function getAreaName(){
   return currentAreaName;
   }

   function setAreaName(tempAreaName){
   currentAreaName=tempAreaName;
   }

   function rightClickItem(itemId){

	    tree.selectItem(itemId);

	    if(tree.getLevel(itemId)==2){
		    if(itemId.indexOf("_")>-1){
	         currentBuildingId=itemId.substring(itemId.indexOf("_")+1,itemId.length);
	         }else{
		    currentBuildingId=itemId;
		    }
	    hidden2menu('quick_rightmenu')
	     ShowContextMenu(event,'quick_rightmenu2');
	    } else if(tree.getLevel(itemId)==1){
	    currentBuildingId='';
	      if(itemId.indexOf("_")>-1){
	         document.getElementById("areaId").value=itemId.substring(itemId.indexOf("_")+1,itemId.length);
	         }else{
		    document.getElementById("areaId").value=itemId;
		    }
	     hidden2menu('quick_rightmenu2')
	     ShowContextMenu(event,'quick_rightmenu');
	    }

   }

   function callbackTree(){
    tree.openItem();
    tree.selectItem();
   	var itemId = tree.getSelectedItemId();   //id获得
   	selectItem(itemId);
   }

   function openBuidingAdd(){


   currentIsEdit="add";
      var url = "${ctx}/house_buildingAction.do?method=initBuildingAdd&hasMoreProject="+hasMoreProject+"&areaId="+document.getElementById("areaId").value;
		top.windowOpen(url, "buidingAdd", "${key.building_add}", 550, 800);

   }

   function openBuidingEidt(){

    if(currentBuildingId == '')
	  {
	   Alert('${key.tipsBySelect}');
	   return false;
	  }

    currentIsEdit="edit";
      var url = "${ctx}/house_buildingAction.do?method=initBuildingEdit&hasMoreProject="+hasMoreProject+"&buildingId="+currentBuildingId+"&areaId="+document.getElementById("areaId").value;
		top.windowOpen(url, "buidingEdit", "${key.building_edit}", 550, 800);

   }

   function openAreaEdit(){
   	  var areaId = document.getElementById("areaId").value;
	  if(areaId == ''|| areaId == null)
	  {
	   Alert('${key.tipsBySelect}');
	   return false;
	  }
		var url = "${ctx}/house_areaAction.do?method=initAreaBaseEdit&areaId=" + areaId;
		top.windowOpen(url,"areaBaseEdit","${key.area_edit}",530,700,true,"areaBaseEditFrameid");
   }

   function deleteBuiding(){

     if(currentBuildingId == '')
	  {
	   Alert('${key.tipsBySelect}');
	   return false;
	  }

     currentIsEdit="delete";
     AskConfirm("${key.tipsByDeleteConfirm}","main","${ctx}/house_buildingAction.do?method=deleteBuilding&buildingId="+currentBuildingId);

   }
	//设置按钮状态,flag为true时,新建按钮不做任何修改,修改按钮onclick变成修改楼盘,删除按钮不可用
	//flag为flase时,新建按钮不做任何修改,修改按钮 onclick变成修改楼盘,删除按钮可用
	function processButtonStatus(flag){
		if(flag){
			document.getElementById("editButton").onclick = openAreaEdit;  //设置修改按钮单击事件
			document.getElementById("deleteButton").onclick = null;
		}else{
			document.getElementById("editButton").onclick = openBuidingEidt;  //设置修改按钮单击事件
			document.getElementById("deleteButton").onclick = deleteBuiding;
		}
	}
</script>
</head>

<body>
<form name="searchBuildingForm" id="searchBuildingForm" action="#" method="post" target="mainFrame">
<input type="hidden" name="buildingName" value="">
<input type="hidden" name="areaId" value="">
<input type="hidden" name="projectId" value="">

</form>
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="48"><div class="pageNav_bg">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td id="pageNav_leftimg"><img src="${ctx}/images/ico_house_fcxx.gif" width="46" height="47"/></td>
      <td id="navWord"><span class="page_title">${key.house_base_set}</span></td>
      <td class="pageNav_right"><a href="javascript:showFull_in();"><img id="full_image"  src="${ctx}/images/ico_fullscreen.gif" border="0"/></a></td>
    </tr>
  </table>

</div></td>
  </tr>
</table>
<div class="container2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <td width="19%" valign="top">

<table width="100%" valign="right" border="0" align="right" cellpadding="0" cellspacing="0"  >
  <tr>
    <td  valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="outside_border" >
	 <tr>
        <td valign="top" ><table width="100%" height="496" border="0" cellpadding="0" cellspacing="0" id=topadcontent_10>

		  <tr>
              <td class="bg_toolBar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="40%">&nbsp;</td>
                  <td width="60%" align="right"><!--------------------------右边图标01----------------------------------->

                    <table border="0" cellpadding="0" cellspacing="0" id="ico3" >
                      <tr>
                       <pms:AuthTag authName="house_buildingAction.do?method=initBuildingAdd">
                        <td class="toolbarico" ><a href="#"  onclick="openBuidingAdd();" onfocus="this.blur()"><img src="${ctx}/images/ico_newfile.gif" alt="新建" width="16" height="16" border="0" align="absbottom" /></a></td>
 						</pms:AuthTag>
 						<pms:AuthTag authName="house_buildingAction.do?method=initBuildingEdit">
 						<td class="toolbarico"><a id="editButton" href="#"  onclick="openBuidingEidt();" onfocus="this.blur()"><img src="${ctx}/images/ico_amend.gif" border="0" align="absbottom" alt="修改"/></a></td>
                        </pms:AuthTag>
                        <pms:AuthTag authName="house_buildingAction.do?&method=deleteBuilding">
                        <td class="toolbarico"><a id="deleteButton"  href="#" onClick="deleteBuiding();" onFocus="this.blur()"><img src="${ctx}/images/ico_delete.gif" alt="删除" width="16" height="16" border="0" align="absbottom"></a></td>
                        </pms:AuthTag>
                        </tr>
                    </table>
                    <!--------------------------右边图标02----------------------------------->
                    <!--------------------------右边图标end----------------------------------->                  </td>
                </tr>
              </table></td>
            </tr>

          <tr>
            <td valign="top">

			<div id="house_tree" style="overflow:auto;width:100%;height:454px;"></div>
			<pms:AuthTag authName="house_houseAction.do?method=housesIconList">
			   <pms:AuthTag authName="house_buildingAction.do?method=initBuildingDetail">
			   <script type="text/javascript">
                allowBuildView=true;


               </script>
			   </pms:AuthTag>
			</pms:AuthTag>
<script type="text/javascript">

        try {
        var tree=new dhtmlXTreeObject("house_tree","100%","100%",0);
		tree.setImagePath("${ctx}/images/tree/");
		tree.setOnClickHandler(selectItem);
		tree.setOnRightClickHandler(rightClickItem);
		tree.loadXML("${ctx}/house_areaAction.do?method=getAreaTreeData&allowBuildView="+allowBuildView,callbackTree);
		} catch(e) {

		}

</script>

			</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table></td>
<td  width="81%" align="center" valign="top"><iframe src="#" name="mainFrame" id="mainFrame" width="100%"  height="498px"  frameborder="0" border="0"  scroll="no" ></iframe></td>
  </tr>
</table>
</div>
<div id="quick_rightmenu2" style="display:none;" oncontextmenu="return false" class="quick_menu2"
onMouseOver="showmy2menu('quick_rightmenu2')"  onMouseOut="hidden2menu('quick_rightmenu2')">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="grid_quickMenu_bg">
                      <tr>
                        <td><table width="100%" border="0" cellpadding="2" cellspacing="0">
                         <pms:AuthTag authName="house_buildingAction.do?method=initBuildingEdit">
                            <tr>
                              <td class="quickMenu_toolbarico"><a href="#"  onClick="openBuidingEidt();" onFocus="this.blur()"><img src="${ctx}/images/ico_amend.gif" border="0" align="absbottom" alt="修改"/>&nbsp;${key.modify}</a></td>
                            </tr>
                          </pms:AuthTag>
                          <pms:AuthTag authName="house_buildingAction.do?&method=deleteBuilding">
                            <tr>
                              <td class="quickMenu_toolbarico"><a href="#" onClick="deleteBuiding();" onFocus="this.blur()"><img src="${ctx}/images/ico_delete.gif" alt="" width="16" height="16" border="0" align="absbottom"> ${key.delete}</a></td>
                            </tr>
                           </pms:AuthTag>
                        </table></td>
                      </tr>
                    </table>
<script type="text/javascript">

	var div1=document.getElementById('quick_rightmenu2');
	if(div1.getElementsByTagName("tr").length==1){
	div1.innerHTML="";
	}
</script>

</div>

<div id="quick_rightmenu" style="display:none;" oncontextmenu="return false" class="quick_menu2" onMouseOver="showmy2menu('quick_rightmenu')"  onMouseOut="hidden2menu('quick_rightmenu')" >
                      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="grid_quickMenu_bg">
                        <tr>
                          <td><table width="100%" border="0" cellpadding="2" cellspacing="0">
                          <pms:AuthTag authName="house_areaAction.do?method=initAreaBaseEdit">
                               <tr>
                                <td class="quickMenu_toolbarico"><a href="#"  onClick="openAreaEdit();"onFocus="this.blur()"><img src="${ctx}/images/ico_amend.gif" border="0" align="absbottom" alt="修改"/>&nbsp;${key.area_edit}</a></td>
                              </tr>
                          </pms:AuthTag>
                          <pms:AuthTag authName="house_buildingAction.do?method=initBuildingAdd">
							  <tr>
                                <td class="quickMenu_toolbarico"><a href="#"  onClick="openBuidingAdd();"onFocus="this.blur()"><img src="${ctx}/images/ico_newfile.gif" border="0" align="absbottom" alt="新建"/>&nbsp;${key.building_add}</a></td>
                              </tr>
                          </pms:AuthTag>
                          </table></td>
                        </tr>
                      </table>

<script type="text/javascript">

	var div1=document.getElementById('quick_rightmenu');
	if(div1.getElementsByTagName("tr").length==1){
	div1.innerHTML="";
	}
</script>

</div>


</body>
</html>
